/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ListaPeliculas.java
 *
 * Created on 14/06/2011, 09:30:20 PM
 */

package guiKiosco;

import java.util.List;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
import logica.Fabrica;
import logica.IKiosco;
import util.datatypes.DTPelicula;

/**
 *
 * @author bruno
 */
public class ListaPeliculas extends javax.swing.JFrame {

    private DefaultListModel peliculas;

    public ListaPeliculas() {
        initComponents();

        this.setSize(1024, 768);
        this.setLocationRelativeTo(null);

        cargarListaPeliculas();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        listPeliculas = new javax.swing.JList();
        pSuperior = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        btnSiguiente = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        listPeliculas.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        listPeliculas.setFont(new java.awt.Font("Arial", 3, 22));
        listPeliculas.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        listPeliculas.setNextFocusableComponent(btnSiguiente);
        listPeliculas.setSelectionBackground(new java.awt.Color(31, 90, 221));
        listPeliculas.setSelectionForeground(new java.awt.Color(254, 254, 254));
        jScrollPane1.setViewportView(listPeliculas);

        getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jLabel1.setFont(new java.awt.Font("Arial", 1, 36));
        jLabel1.setText("Lista de peliculas");

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/guiKiosco/resources/cinema.png"))); // NOI18N

        jLabel3.setFont(new java.awt.Font("Arial", 0, 24));
        jLabel3.setText("Seleccione una");

        javax.swing.GroupLayout pSuperiorLayout = new javax.swing.GroupLayout(pSuperior);
        pSuperior.setLayout(pSuperiorLayout);
        pSuperiorLayout.setHorizontalGroup(
            pSuperiorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pSuperiorLayout.createSequentialGroup()
                .addGap(62, 62, 62)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(56, 56, 56)
                .addGroup(pSuperiorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel1))
                .addContainerGap(301, Short.MAX_VALUE))
        );
        pSuperiorLayout.setVerticalGroup(
            pSuperiorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pSuperiorLayout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3)
                .addContainerGap())
            .addGroup(pSuperiorLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)
                .addGap(23, 23, 23))
        );

        getContentPane().add(pSuperior, java.awt.BorderLayout.PAGE_START);

        btnSiguiente.setBackground(new java.awt.Color(242, 241, 240));
        btnSiguiente.setFont(new java.awt.Font("Arial", 0, 48));
        btnSiguiente.setIcon(new javax.swing.ImageIcon(getClass().getResource("/guiKiosco/resources/arrow_right.png"))); // NOI18N
        btnSiguiente.setBorder(null);
        btnSiguiente.setBorderPainted(false);
        btnSiguiente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSiguienteActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(671, Short.MAX_VALUE)
                .addComponent(btnSiguiente, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(29, 29, 29))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(32, Short.MAX_VALUE)
                .addComponent(btnSiguiente, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        getContentPane().add(jPanel1, java.awt.BorderLayout.PAGE_END);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnSiguienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSiguienteActionPerformed

        if (listPeliculas.getSelectedValue() != null) {

            DTPelicula dtPelicula = (DTPelicula)listPeliculas.getSelectedValue();

            ListaFunciones frm = new ListaFunciones(dtPelicula);
            frm.setVisible(true);

            this.setVisible(false);
        }else{

            JOptionPane.showMessageDialog(null, "Debe seleccionar una pelicula para continuar");
            
        }

    }//GEN-LAST:event_btnSiguienteActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ListaPeliculas().setVisible(true);
            }
        });
    }

    private void cargarListaPeliculas(){
        IKiosco i = Fabrica.getIKiosco();

        List<DTPelicula> lstPeliculas = i.listarPeliculas();

        peliculas = new DefaultListModel();
        
        for (DTPelicula dtPelicula : lstPeliculas) {
            peliculas.addElement(dtPelicula);
        }
        
        listPeliculas.setModel(peliculas);

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnSiguiente;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JList listPeliculas;
    private javax.swing.JPanel pSuperior;
    // End of variables declaration//GEN-END:variables

}
